﻿@model  Authentication.Model.ViewModel.Customer.ShopInfoViewModel
<ul class="breadcrumb">
    <li>
        <i class="icon-home"></i>
        <a href="/">Customer</a>
        <i class="icon-angle-right"></i>
    </li>
    <li>
        <i class="icon-link"></i>
        <a href="#">Shops infomation</a>
    </li>
</ul>
<!--/span-->
<div class="row-fluid">
    <div class="box span12">
        <div class="box-header" data-original-title>
            <h2><i class="halflings-icon th-large"></i><span class="break"></span>Shops infomation</h2>
            <div class="box-icon">
                <a href="#" class="btn-minimize"><i class="halflings-icon chevron-up"></i></a>
            </div>
        </div>
        <div class="box-content">
            <table class="table table-striped bootstrap-datatable datatable" id="dataTables-1">
                <thead>
                    <tr>
                        <th class="text-left all">ShopCode</th>
                        <th class="text-left all">ShopName</th>
                        <th class="text-left none">RegId</th>
                        <th class="text-left none">Channel</th>
                        <th class="text-left none">ShopType</th>
                        <th class="text-left">BillToCode</th>
                        <th class="text-left">BillToName</th>
                        <th class="text-left">OwnerName</th>
                        <th class="text-left">OwnerEmail</th>
                        <th class="text-left none">ProvinceCode</th>
                        <th class="text-left">ProvinceName</th>
                        <th class="text-left none">DistCode</th>
                        <th class="text-left">DistName</th>
                        <th class="text-left">Address</th>
                        <th class="text-left">CellNo1</th>
                        <th class="text-left">CellNo2</th>
                        <th class="text-left all" style="width: 60px;">Action</th>
                        <th class="text-left none">ISDNNo</th>
                    </tr>
                </thead>
                <tbody></tbody>
            </table>
            @if (true || Model.IsSupperAdmin)
            {
                <div class="form-actions">
                    <button id="btnRegister" type="submit" class="btn btn-success btn-responsive"><i class="icon-plus"></i>&nbsp;Register shop</button>
                    <button id="btnImport" type="submit" class="btn btn-success btn-responsive" disabled="disabled"><i class="icon-upload-alt"></i>&nbsp;Import data</button>
                    <button id="btnExport" type="submit" class="btn btn-success btn-responsive" disabled="disabled"><i class="icon-download-alt"></i>&nbsp;Export data</button>
                </div>
            }
        </div>
    </div>
</div>
<!--/row-->
@if (true)
{
    using (Html.BeginForm("shopinfo", "customer", FormMethod.Post, new { @class = "form-horizontal", name = "Update", id = "Update" }))
    {
    <div id="shopEditor" class="modal box brown fade">
        <div class="box-header">
            <h2><i class="halflings-icon white home"></i><span class="break"></span>Shop Infomation</h2>
            <div class="box-icon">
                <a data-dismiss="modal" class="close"><i class="halflings-icon white remove"></i></a>
            </div>
        </div>
        <div class="box-content">
            <fieldset>
                <div class="validation-summary alert alert-error">
                    <a class="close" data-dismiss="alert">×</a>
                    <h5 class="alert-heading">Shop info validate</h5>
                    @Html.AntiForgeryToken()
                    @Html.ValidationSummary()
                </div>
                <div class="control-group">
                    <label class="control-label" for="ShopCode">Shop Code/ Name:</label>
                    <div class="controls">
                        @Html.TextBoxFor(m => m.ShopCode, new { @class = "span3" })
                        @Html.TextBoxFor(m => m.ShopName, new { @class = "span7" })
                        @Html.Hidden("btnClick")
                    </div>
                </div>
                <div class="control-group">
                    <label class="control-label" for="BillTo">Bill to Code/ Name:</label>
                    <div class="controls">
                        @Html.TextBoxFor(m => m.BillTo, new { @class = "billto-val span4" })
                        @Html.TextBoxFor(m => m.BillToName, new { @class = "billto-text span6", disabled = "disabled" })
                    </div>
                </div>
                <div class="control-group">
                    @Html.LabelFor(m => m.RegionIdentifier, new { @class = "control-label" })
                    <div class="controls">
                        @Html.DropDownListFor(m => m.RegionIdentifier, new SelectList(Authentication.Web.Controller.Helper.Regions, "RegionIdentifier", "RegionName"), new { @class = "span4 region-val" })
                    </div>
                </div>
                <div class="control-group">
                    <label class="control-label" for="ProvinceIdentifier">Provinces/Districts:</label>
                    <div class="controls">
                        @Html.HiddenFor(m => m.Active)
                        @Html.HiddenFor(m => m.ProvinceIdentifier, new { @class = "province-val" })
                        @Html.HiddenFor(m => m.DistrictIdentifier, new { @class = "district-val" })
                        @Html.TextBoxFor(m => m.ProvinceName, string.Empty, new { @class = "span4 province-text" })
                        @Html.TextBoxFor(m => m.DistrictName, string.Empty, new { @class = "span6 district-text" })
                    </div>
                </div>
                <div class="control-group">
                    @Html.LabelFor(m => m.Address, new { @class = "control-label" })
                    <div class="controls">
                        @Html.TextBoxFor(m => m.Address, new { @class = "span10" })
                    </div>
                </div>
                <div class="control-group">
                    <label class="control-label" for="OwnerName">Owner Name/Email:</label>
                    <div class="controls">
                        @Html.TextBoxFor(m => m.OwnerName, new { @class = "span5" })
                        @Html.TextBoxFor(m => m.OwnerEmail, new { @class = "span5" })
                    </div>
                </div>
                <div class="control-group">
                    <label class="control-label" for="CellNo1">Cell No.1/No.2:</label>
                    <div class="controls">
                        @Html.TextBoxFor(m => m.CellNo1, new { @class = "span5" })
                        @Html.TextBoxFor(m => m.CellNo2, new { @class = "span5" })
                    </div>
                </div>

                <div class="control-group">
                    @Html.LabelFor(m => m.IsdnNo, new { @class = "control-label" })
                    <div class="controls">
                        @Html.TextBoxFor(m => m.IsdnNo, new { @class = "span5" })
                    </div>
                </div>
                <div class="control-group">
                    <label class="control-label" for="ShopType">ShopType/Channel:</label>
                    <div class="controls">
                        @Html.DropDownListFor(m => m.ShopType, Authentication.Web.Controller.Helper.ShopTypes, "-- Select shop type --", new { @class = "span5" })
                        @Html.DropDownListFor(m => m.Channel, Authentication.Web.Controller.Helper.Channels, "-- Select Channel --", new { @class = "span5" })
                    </div>
                </div>
                <div class="form-actions modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                    <input type="submit" name="btnUpdate" id="btnUpdate" class="btn btn-primary" value="Save changes" />
                </div>
            </fieldset>
        </div>
    </div>
    <!--/editor-->
    }
}
@section scripts
{
    @if (true)
    {
        <script>
            $(document).ready(function () {
                var table = $('#dataTables-1').dataTable({
                    "bServerSide": true,
                    "bProcessing": true,
                    "responsive": true,
                    "bAutoWidth": false,
                    oLanguage: {
                        sProcessing: "<img src='http://www.arabianbusiness.com/skins/ab.main/gfx/loading_spinner.gif'/>"
                    },
                    "aLengthMenu": [10, 30, 50, 100],
                    "pageLength": 30,
                    "sAjaxSource": '@Url.Action("ShopInfoData")',
                    "fnServerData": function (sSource, aoData, fnCallback) {
                        $.ajax({
                            "dataType": 'json',
                            "type": "POST",
                            "url": sSource,
                            "data": aoData,
                            "success": fnCallback
                        });
                    },
                    "sDom": "<'row-fluid'<'span6'l><'span6'f>r>t<'row-fluid'<'dataTables_wrapper'ip>>",
                    "sPaginationType": "bootstrap",//"full_numbers",
                    "aoColumns": [
                                { "sName": "ShopCode", "bSortable": false },
                                { "sName": "ShopName", "bSortable": false },
                                { "sName": "RegId", "bSortable": false },
                                { "sName": "Channel", "bSortable": false },
                                { "sName": "ShopType", "bSortable": false },
                                { "sName": "BillToCode", "bSortable": false },
                                { "sName": "BillToName", "bSortable": false },
                                { "sName": "OwnerName", "bSortable": false },
                                { "sName": "OwnerEmail", "bSortable": false },
                                { "sName": "ProvinceCode", "bSortable": false },
                                { "sName": "ProvinceName", "bSortable": false },
                                { "sName": "DistCode", "bSortable": false },
                                { "sName": "DistName", "bSortable": false },
                                { "sName": "Address", "bSortable": false },
                                { "sName": "CellNo1", "bSortable": false },
                                { "sName": "CellNo2", "bSortable": false },
                                { "sName": "active", "bSortable": false },
                                { "sName": "ISDNNo", "bSortable": false }],
                    "aoColumnDefs": [{
                        "aTargets": [16],
                        "mData": null,
                        "mRender": function (data, type, full) {
                            var iconClass = "eye-open", btnClass = "btn-primary";
                            if (!full[16]) {
                                iconClass = "eye-close";
                                btnClass = "btn-danger";
                            }
                            var jsparam = '\'' + full[0] + '\',\'' + full[1] + '\',\'' + full[2] + '\',\'' + full[3] + '\',\'' + full[4] + '\',\'' + full[5] + '\',\'' + full[7] + '\',\'' + full[8] + '\',\'' + full[9] + '\',\'' + full[10] + '\',\'' + full[11] + '\',\'' + full[12] + '\',\'' + full[13] + '\',\'' + full[14] + '\',\'' + full[15] + '\',\'' + full[16] + '\'';
                            return '<button class=\"btn btn-small btn-success\" onclick=\"showShopEditor(' + jsparam + ');\"><i class=\"halflings-icon white edit\"></i></button> <button class=\"btn btn-small ' + btnClass + '\" onclick=\"activeShop(\'' + full[0] + '\',' + full[16] + ');\"><i class=\"halflings-icon white ' + iconClass + '\"></i></button>';
                        }
                    }]
                });
            });

            function showShopEditor(shopcode, shopname, regid, channel, shoptype, billcode, ownername, owneremail, province, provincename, district, districtname, address, cellno1, cellno2, active) {
                $('#btnClick').val(null);
                $('#ShopCode').val(shopcode);
                $('#BillTo').val(billcode);
                $('#ShopName').val(shopname);
                $('#RegId').val(regid);
                $('#ShopType').val(shoptype);
                $('#Channel').val(channel);
                $('#OwnerName').val(ownername);
                $('#OwnerEmail').val(owneremail);
                $('#ProvinceIdentifier').val(province);
                $('#DistrictIdentifier').val(district);
                $('#ProvinceName').val(provincename);
                $('#DistrictName').val(districtname);
                $('#Address').val(address);
                $('#CellNo1').val(cellno1);
                $('#CellNo2').val(cellno2);
                //$('#IsdnNo').val(isdnno);
                $('#Active').val(active);
                $("#shopEditor").modal('show');
                $.post('/system/billtoterm', { term: $('#BillTo').val() }, function (data) {
                    console.log()
                    if (data.IsSuccess && data.Records[0] != null && data.Records[1] == null) $('#BillToName').val(data.Records[0].FullName);
                    else $('#BillToName').val('');
                });
            }

            function activeShop(id, active) {
                var confirmText = 'The selected shop will be disabled, are you really?';
                if (!active) confirmText = 'The selected shop will be enabled, are you really?';
                ConfirmDlg('Confirm this data...!', confirmText, successFunction = function () {
                    $.post('@Authentication.Configuration.SystemConfiguration.ActiveShopAction', { code: id, active: active }, function (data) {
                        if (data.IsSuccess) reload();
                        else alert(data.ErrorMessage);
                    });
                });
            }

            $("#btnRegister").click(function () {
                showShopEditor(null, null, null, null, null, null, null, null, null, null, null, null, null, null);
                $('#btnClick').val('btnNewShop');
            });
        </script>
    }
}